<?php 
/**
 * 侧边栏组件、页面模块
 */
if(!defined('EMLOG_ROOT')) {exit('error!');} 
?>
<?php
//widget：blogger
function widget_blogger($title){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');
	$name = $user_cache[1]['mail'] != '' ? "<a href=\"mailto:".$user_cache[1]['mail']."\">".$user_cache[1]['name']."</a>" : $user_cache[1]['name'];?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul id="bloggerinfo">
	<div id="bloggerinfoimg">
	<?php if (!empty($user_cache[1]['photo']['src'])): ?>
	<img src="<?php echo BLOG_URL.$user_cache[1]['photo']['src']; ?>" width="<?php echo $user_cache[1]['photo']['width']; ?>" height="<?php echo $user_cache[1]['photo']['height']; ?>" alt="blogger" />
	<?php endif;?>
	</div>
	<p><b><?php echo $name; ?></b>
	<?php echo $user_cache[1]['des']; ?></p>
	</ul>
	</li>
<?php }?>
<?php
//widget：日历
function widget_calendar($title){ ?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<div id="calendar">
	</div>
	<script>sendinfo('<?php echo Calendar::url(); ?>','calendar');</script>
	</li>
<?php }?>
<?php
//widget：标签
function widget_tag($title){
	global $CACHE;
	$tag_cache = $CACHE->readCache('tags');?>
	<div class="panel-heading"><?php echo $title; ?></div>
	<div class="panel-body">
    <article class="media">
	<?php foreach($tag_cache as $value): ?>
		<span style="font-size:<?php echo $value['fontsize']; ?>pt; line-height:30px;">
		<a href="<?php echo Url::tag($value['tagurl']); ?>" title="<?php echo $value['usenum']; ?> 篇文章"><?php echo $value['tagname']; ?></a></span>
	<?php endforeach; ?>
	</article>
	</div>
<?php }?>
<?php
//widget：分类
function widget_sort($title){
	global $CACHE;
	$sort_cache = $CACHE->readCache('sort'); ?>
	<div class="panel-heading"><?php echo $title; ?></div>
	<div class="panel-body">
    <article class="media">
	<?php
	foreach($sort_cache as $value):
		if ($value['pid'] != 0) continue;
	?>
	<div class="media-body"> 
	<a class="font-semibold" href="<?php echo Url::sort($value['sid']); ?>"><?php echo $value['sortname']; ?>(<?php echo $value['lognum'] ?>)</a>
	<?php if (!empty($value['children'])): ?>
		<article class="media">
		<?php
		$children = $value['children'];
		foreach ($children as $key):
			$value = $sort_cache[$key];
		?>
		<div class="media-body">
			<a class="font-semibold" href="<?php echo Url::sort($value['sid']); ?>"><?php echo $value['sortname']; ?>(<?php echo $value['lognum'] ?>)</a>
		</div>
		<?php endforeach; ?>
		</article>
    </div>
	<?php endif; ?>
	<?php endforeach; ?>
	</article>
	</div>
<?php }?>
<?php
//widget：最新微语
function widget_twitter($title){
	global $CACHE; 
	$newtws_cache = $CACHE->readCache('newtw');
	$istwitter = Option::get('istwitter');
	?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul id="twitter">
	<?php foreach($newtws_cache as $value): ?>
	<?php $img = empty($value['img']) ? "" : '<a title="查看图片" class="t_img" href="'.BLOG_URL.str_replace('thum-', '', $value['img']).'" target="_blank">&nbsp;</a>';?>
	<li><?php echo $value['t']; ?><?php echo $img;?><p><?php echo smartDate($value['date']); ?></p></li>
	<?php endforeach; ?>
    <?php if ($istwitter == 'y') :?>
	<p><a href="<?php echo BLOG_URL . 't/'; ?>">更多&raquo;</a></p>
	<?php endif;?>
	</ul>
	</li>
<?php }?>
<?php
//widget：最新评论
function widget_newcomm($title){
	global $CACHE; 
	$com_cache = $CACHE->readCache('comment');
	?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul id="newcomment">
	<?php
	foreach($com_cache as $value):
	$url = Url::comment($value['gid'], $value['page'], $value['cid']);
	?>
	<li id="comment"><?php echo $value['name']; ?>
	<br /><a href="<?php echo $url; ?>"><?php echo $value['content']; ?></a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?>
<?php
//widget：最新文章
function widget_newlog($title){
	global $CACHE; 
	$newLogs_cache = $CACHE->readCache('newlog');
	?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul id="newlog">
	<?php foreach($newLogs_cache as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?>
<?php
//widget：热门文章
function widget_hotlog($title){
	$index_hotlognum = Option::get('index_hotlognum');
	$Log_Model = new Log_Model();
	$randLogs = $Log_Model->getHotLog($index_hotlognum);?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul id="hotlog">
	<?php foreach($randLogs as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?>
<?php
//widget：随机文章
function widget_random_log($title){
	$index_randlognum = Option::get('index_randlognum');
	$Log_Model = new Log_Model();
	$randLogs = $Log_Model->getRandLog($index_randlognum);?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul id="randlog">
	<?php foreach($randLogs as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?>
<?php
//widget：搜索
function widget_search($title){ ?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul id="logsearch">
	<form name="keyform" method="get" action="<?php echo BLOG_URL; ?>index.php">
	<input name="keyword" class="search" type="text" />
	</form>
	</ul>
	</li>
<?php } ?>
<?php
//widget：归档
function widget_archive($title){
	global $CACHE; 
	$record_cache = $CACHE->readCache('record');
	?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul id="record">
	<?php foreach($record_cache as $value): ?>
	<li><a href="<?php echo Url::record($value['date']); ?>"><?php echo $value['record']; ?>(<?php echo $value['lognum']; ?>)</a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php } ?>
<?php
//widget：自定义组件
function widget_custom_text($title, $content){ ?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul>
	<?php echo $content; ?>
	</ul>
	</li>
<?php } ?>
<?php
//widget：链接
function widget_link($title){
	global $CACHE; 
	$link_cache = $CACHE->readCache('link');
    //if (!blog_tool_ishome()) return;#只在首页显示友链去掉双斜杠注释即可
	?>
	<li>
	<h3><span><?php echo $title; ?></span></h3>
	<ul id="link">
	<?php foreach($link_cache as $value): ?>
	<li><a href="<?php echo $value['url']; ?>" title="<?php echo $value['des']; ?>" target="_blank"><?php echo $value['link']; ?></a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?> 
<?php
//blog：导航
function blog_navi(){
	global $CACHE; 
	$navi_cache = $CACHE->readCache('navi');
	?>
	<?php
	foreach($navi_cache as $value):

        if ($value['pid'] != 0) {
            continue;
        }
		if($value['url'] == ROLE_ADMIN && (ROLE == ROLE_ADMIN || ROLE == ROLE_WRITER)):
			?>
			<li >
			<a href="<?php echo BLOG_URL; ?>admin/" class="auto">
			<span class="pull-right text-muted">
                          <i class="fa fa-angle-left text"></i>
                          <i class="fa fa-angle-down text-active"></i>
                        </span>
                        <i class="icon-chemistry icon">
                        </i>
						<span>管理站点</span></a></li>
			<li >
			<a href="<?php echo BLOG_URL; ?>admin/?action=logout" class="auto">
			<span class="pull-right text-muted">
                          <i class="fa fa-angle-left text"></i>
                          <i class="fa fa-angle-down text-active"></i>
                        </span>
                        <i class="icon-chemistry icon">
                        </i>
						<span>退出</span></a></li>
			<?php 
			continue;
		endif;
		$newtab = $value['newtab'] == 'y' ? 'target="_blank"' : '';
        $value['url'] = $value['isdefault'] == 'y' ? BLOG_URL . $value['url'] : trim($value['url'], '/');
        $current_tab = BLOG_URL . trim(Dispatcher::setPath(), '/') == $value['url'] ? 'current' : 'common';
		?>
		<li >
			<a href="<?php echo $value['url']; ?>" class="auto" <?php echo $newtab;?>>
			<span class="pull-right text-muted">
                          <i class="fa fa-angle-left text"></i>
                          <i class="fa fa-angle-down text-active"></i>
                        </span>
                        <i class="icon-chemistry icon">
                        </i>
						<span>
						<?php echo $value['naviname']; ?>
						</span></a>
			<?php if (!empty($value['children'])) :?>
            <ul class="nav dk text-sm">
                <?php foreach ($value['children'] as $row){
                        echo '<li><a href="'.Url::sort($row['sid']).'" class="auto"><i class="fa fa-angle-right text-xs"></i><span>'.$row['sortname'].'</span></a></li>';
                }?>
			</ul>
            <?php endif;?>
            <?php if (!empty($value['childnavi'])) :?>
            <ul class="nav dk text-sm">
                <?php foreach ($value['childnavi'] as $row){
                        $newtab = $row['newtab'] == 'y' ? 'target="_blank" class="auto"' : '';
                        echo '<li><a href="' . $row['url'] . ' "\" $newtab >"<i class="fa fa-angle-right text-xs"></i><span> ' . $row['naviname'].'</span></a></li>';
                }?>
			</ul>
            <?php endif;?>
		</li>
	<?php endforeach; ?>
<?php }?>
<?php
//blog：置顶
function topflg($top, $sortop='n', $sortid=null){
    if(blog_tool_ishome()) {
       echo $top == 'y' ? "<img src=\"".TEMPLATE_URL."/images/top.png\" title=\"首页置顶文章\" /> " : '';
    } elseif($sortid){
       echo $sortop == 'y' ? "<img src=\"".TEMPLATE_URL."/images/sortop.png\" title=\"分类置顶文章\" /> " : '';
    }
}
?>
<?php
//blog：编辑
function editflg($logid,$author){
	$editflg = ROLE == ROLE_ADMIN || $author == UID ? '<a href="'.BLOG_URL.'admin/write_log.php?action=edit&gid='.$logid.'" target="_blank">编辑</a>' : '';
	echo $editflg;
}
?>
<?php
//blog：分类
function blog_sort($blogid){
	global $CACHE; 
	$log_cache_sort = $CACHE->readCache('logsort');
	?>
	<?php if(!empty($log_cache_sort[$blogid])): ?>
    <a href="<?php echo Url::sort($log_cache_sort[$blogid]['id']); ?>"><?php echo $log_cache_sort[$blogid]['name']; ?></a>
	<?php endif;?>
<?php }?>
<?php
//blog：文章标签
function blog_tag($blogid){
	global $CACHE;
	$log_cache_tags = $CACHE->readCache('logtags');
	if (!empty($log_cache_tags[$blogid])){
		$tag = '标签:';
		foreach ($log_cache_tags[$blogid] as $value){
			$tag .= "	<a href=\"".Url::tag($value['tagurl'])."\">".$value['tagname'].'</a>';
		}
		echo $tag;
	}
}
?>
<?php
//blog：文章作者
function blog_author($uid){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');
	$author = $user_cache[$uid]['name'];
	$mail = $user_cache[$uid]['mail'];
	$des = $user_cache[$uid]['des'];
	$title = !empty($mail) || !empty($des) ? "title=\"$des $mail\"" : '';
	echo '<a href="'.Url::author($uid)."\" $title>$author</a>";
}
?>
<?php
//blog：相邻文章
function neighbor_log($neighborLog){
	extract($neighborLog);?>
	<?php if($prevLog):?>
	Prev&nbsp;&nbsp;>>&nbsp;&nbsp;<a href="<?php echo Url::log($prevLog['gid']) ?>"><?php echo $prevLog['title'];?></a>
	<?php endif;?>
	<?php if($nextLog && $prevLog):?>
	</br>
	<div class="line b-b"></div>
	<?php endif;?>
	<?php if($nextLog):?>
	Next&nbsp;&nbsp;>>&nbsp;&nbsp;<a href="<?php echo Url::log($nextLog['gid']) ?>"><?php echo $nextLog['title'];?>
	<?php endif;?>
<?php }?>
<?php 
function bg_color(){
		$array_bg = array(
			'1' => 'bg-primary',
			'2' => 'bg-success',
			'3' => 'bg-dark',
			'4' => 'bg-info',
			'5' => 'bg-white'
		);
		echo $array_bg[rand(1,5)];
	}?>
<?php
//guest：评论列表
function guest_comments($comments,$params){
    extract($comments);
    if($commentStacks): ?>
	<?php endif; ?>
	<?php
	$isGravatar = Option::get('isgravatar');
	$comnum = count($comments);
    foreach($comments as $value){
    if($value['pid'] != 0){
    $comnum--;
    }
}
    $page = isset($params[5])?intval($params[5]):1;
    $i= $comnum - ($page - 1)*Option::get('comment_pnum');

	foreach($commentStacks as $cid):
    $comment = $comments[$cid];
	$comment['poster'] = $comment['url'] ? '<a href="'.$comment['url'].'" target="_blank">'.$comment['poster'].'</a>' : $comment['poster'];
	?>
                    <!-- .comment-list -->
                  <section class="comment-list block">
                    <article id="comment-id-<?php echo $comment['cid']; ?>" class="comment-item">
					<a name="<?php echo $comment['cid']; ?>"></a>
                      <a class="pull-left thumb-sm avatar">
                        <i class="fa fa-male time-icon bg-success"></i>
                      </a>
                      <span class="arrow left"></span>
                      <section class="comment-body panel panel-default">
                        <header class="panel-heading bg-white">
                          <a href="#"><?php echo $comment['poster']; ?></a>
                          <label class="label <?php bg_color(); ?> m-l-xs"><?php echo $i; ?> F</label>
                          <span class="text-muted m-l-sm pull-right">
                            <i class="fa fa-clock-o"></i>
                            <?php echo $comment['date']; ?>
                          </span>
                        </header>
                        <div class="panel-body">
                          <div><?php echo $comment['content']; ?></div>
                          <div class="comment-action m-t-sm">
                            <a href="#comment-id-<?php echo $comment['cid']; ?>" onclick="commentReply(<?php echo $comment['cid']; ?>,this)" class="btn btn-default btn-xs">
                              <i class="fa fa-mail-reply text-muted"></i> Reply
                            </a>
                          </div>
                        </div>
                      </section>
                    </article>
		<?php guest_comments_children($comments, $comment['children']);?>
	<?php $i--; endforeach; ?>
                  <div class="text-center">
                    <ul class="pagination pagination">
	    <?php echo $commentPageUrl;?>
                    </ul>
                  </div>
<?php }?>
<?php
//guest：子评论列表
function guest_comments_children($comments, $children){
	$isGravatar = Option::get('isgravatar');
	foreach($children as $child):
	$comment = $comments[$child];
	$userNmae = $comment['poster'];
	$comment['poster'] = $comment['url'] ? '<a href="'.$comment['url'].'" target="_blank">'.$comment['poster'].'</a>' : $comment['poster'];
	global $CACHE; 
	$user_cache = $CACHE->readCache('user');
	if ($comment['mail'] == $user_cache[1]['mail']){?>
                    <!-- / .comment-reply -->
                    <article id="comment-id-<?php echo $comment['cid']; ?>" class="comment-item comment-reply">
					 <a name="<?php echo $comment['cid']; ?>"></a>
				<?php
					 if (!empty($user_cache[1]['photo']['src'])): ?>
                      <a class="pull-left thumb-sm avatar">
                        <img src="<?php echo BLOG_URL.$user_cache[1]['photo']['src']; ?>" alt="<?php echo $name; ?>">
                      </a>
					  <?php endif; ?>
                      <span class="arrow left"></span>
                      <section class="comment-body panel panel-default text-sm">
                        <div class="panel-body">
                          <span class="text-muted m-l-sm pull-right">
                            <i class="fa fa-clock-o"></i>
                            <?php echo $comment['date']; ?>
                          </span>
                          <a href="#"><?php echo $comment['poster']; ?></a>
                          <label class="label bg-dark m-l-xs">Admin</label> 
                          <?php echo $comment['content']; ?> 
						  <div class="comment-action m-t-sm">
						    <a href="#comment-id-<?php echo $comment['cid']; ?>" onclick="commentReply(<?php echo $comment['cid']; ?>,this)" class="btn btn-default btn-xs">
                              <i class="fa fa-mail-reply text-muted"></i> Reply
                            </a>
                          </div>
                        </div>
                      </section>
                    </article>
<?php }else{?>
                    <!-- / .comment-reply -->
                    <article id="comment-id-<?php echo $comment['cid']; ?>" class="comment-item comment-reply">
					 <a name="<?php echo $comment['cid']; ?>"></a>
                      <a class="pull-left thumb-sm avatar">
					  <i class="fa fa-male time-icon bg-success"></i>
					  </a>
                      <span class="arrow left"></span>
                      <section class="comment-body panel panel-default text-sm">
                        <header class="panel-heading">                      
                          <a href="#"><?php echo $comment['poster']; ?></a>
                          <label class="label bg-success m-l-xs"></label> 
                          <span class="text-muted m-l-sm pull-right">
                            <i class="fa fa-clock-o"></i>
                            <?php echo $comment['date']; ?>
                          </span>
                        </header>					
                        <div class="panel-body">
                          <div><?php echo $comment['content']; ?></div>
						  <?php if($comment['level'] < 8): ?>
                          <div class="comment-action m-t-sm">
						    <a href="#comment-id-<?php echo $comment['cid']; ?>" onclick="commentReply(<?php echo $comment['cid']; ?>,this)" class="btn btn-default btn-xs">
                              <i class="fa fa-mail-reply text-muted"></i> Reply
                            </a>
                          </div>
						  <?php endif; ?> 
                        </div>
                      </section>
                    </article>
<?php }?>
       <?php guest_comments_children($comments, $comment['children']);?>
	<?php endforeach; ?>
<?php }?>
<?php
//blog：评论列表
function blog_comments($comments){
    extract($comments);
    if($commentStacks): ?>
	<?php if($comnum):;?>
         <h4 class="m-t-lg m-b">&nbsp;<?php echo $comnum; ?>&nbsp;Comments</h4>
	<?php endif;?>
	<?php endif; ?>
	<section class="comment-list block">
	<?php
	$isGravatar = Option::get('isgravatar');
	foreach($commentStacks as $cid):
    $comment = $comments[$cid];
	$comment['poster'] = $comment['url'] ? '<a href="'.$comment['url'].'" target="_blank">'.$comment['poster'].'</a>' : $comment['poster'];
	?>
	<a name="<?php echo $comment['cid']; ?>"></a>
                    <article id="comment-id-<?php echo $comment['cid']; ?>" class="comment-item">
					<?php if($isGravatar == 'y'): ?>
                      <a class="pull-left thumb-sm">
                        <img src="<?php echo ting_avatar($comment['mail']); ?>" class="img-circle">
                      </a>
					  <?php endif; ?>
                      <section class="comment-body m-b">
                        <header>
                          <a><strong><?php echo $comment['poster']; ?></strong></a>
                          <label class="label bg-info m-l-xs">
                            <a href="#comment-<?php echo $comment['cid']; ?>" onclick="commentReply(<?php echo $comment['cid']; ?>,this)">Reply</a>
                          </label> 
                          <span class="text-muted text-xs block m-t-xs">
                            <?php echo $comment['date']; ?>
                          </span>
                        </header>
                        <div class="m-t-sm"><?php echo $comment['content']; ?></div>
                      </section>
                    </article>
	<?php blog_comments_children($comments, $comment['children']); ?>
	<?php endforeach; ?>
    <div id="pagenavi">
	    <?php echo $commentPageUrl;?>
    </div>
	</section>
<?php }?>
<?php
//blog：子评论列表
function blog_comments_children($comments, $children){
	$isGravatar = Option::get('isgravatar');
	foreach($children as $child):
	$comment = $comments[$child];
	$comment['poster'] = $comment['url'] ? '<a href="'.$comment['url'].'" target="_blank">'.$comment['poster'].'</a>' : $comment['poster'];
	?>
                    <!-- .comment-reply -->
                    <article id="comment-id-<?php echo $comment['cid']; ?>" class="comment-item comment-reply">
					<a name="<?php echo $comment['cid']; ?>"></a>
					<?php if($isGravatar == 'y'): ?>
                      <a class="pull-left thumb-sm">
                        <img src="<?php echo ting_avatar($comment['mail']); ?>" class="img-circle">
                      </a>
					  <?php endif; ?>
                      <section class="comment-body m-b">
                        <header>
                          <a><strong><?php echo $comment['poster']; ?></strong></a>
						  <?php if($comment['level'] < 8): ?>
                          <label class="label bg-dark m-l-xs">
                           <a href="#comment-<?php echo $comment['cid']; ?>" onclick="commentReply(<?php echo $comment['cid']; ?>,this)">Reply</a>
                          </label>
						  <?php endif; ?>
                          <span class="text-muted text-xs block m-t-xs">
                           <?php echo $comment['date']; ?>
                          </span>
                        </header>
                        <div class="m-t-sm"><?php echo $comment['content']; ?></div>
                      </section>
                    </article>
       <?php blog_comments_children($comments, $comment['children']);?>
	<?php endforeach; ?>
<?php }?>
<?php
//blog：发表评论表单
function blog_comments_post($logid,$ckname,$ckmail,$ckurl,$verifyCode,$allow_remark,$log_box_type){
	if($allow_remark == 'y'):
		if($log_box_type == 'log'){ ?>
	<div id="comment-place">
	<div class="comment-post" id="comment-post">
		<div class="cancel-reply" id="cancel-reply" style="display:none"><a href="javascript:void(0);" onclick="cancelReply()">Cancel</a></div>
				  <h4 class="m-t-lg m-b">Leave a comment</h4>
                  <form method="post" name="commentform" action="<?php echo BLOG_URL; ?>index.php?action=addcom" id="commentform">
				  <input type="hidden" name="gid" value="<?php echo $logid; ?>" />
			      <?php if(ROLE == ROLE_VISITOR): ?>
                    <div class="form-group pull-in clearfix">
                      <div class="col-sm-6">
                        <label for="author">Your name</label>
                        <input type="text" class="form-control" placeholder="Name" name="comname" maxlength="49" value="<?php echo $ckname; ?>" size="22" tabindex="1">
                      </div>
                      <div class="col-sm-6">
                        <label for="email">Email</label>
                        <input type="email" class="form-control" placeholder="Enter email" name="commail"  maxlength="128"  value="<?php echo $ckmail; ?>" size="22" tabindex="2">
                      </div>
                    </div>
					<?php endif; ?>
                    <div class="form-group">
                      <label>Comment</label>
                      <textarea class="form-control" rows="5" placeholder="Type your comment" name="comment" id="comment" rows="10" tabindex="4"></textarea>
                    </div>
                    <div class="form-group">
                      <?php echo $verifyCode; ?><button type="submit" class="btn btn-success" id="comment_submit" tabindex="6">Submit comment</button>
					  <input type="hidden" name="pid" id="comment-pid" value="0" size="22" tabindex="1"/>
                    </div>
                  </form>
	</div>
	</div>
	<?php }if($log_box_type == 'guest'){ ?>
	            <div id="comment-place">
	            <div class="comment-post" id="comment-post">
		        <div class="cancel-reply" id="cancel-reply" style="display:none"><a href="javascript:void(0);" onclick="cancelReply()">Cancel</a></div>
                <form method="post" name="commentform" action="<?php echo BLOG_URL; ?>index.php?action=addcom" id="commentform">
				<input type="hidden" name="gid" value="<?php echo $logid; ?>" />
				<?php if(ROLE == ROLE_VISITOR): ?>
                  <div class="form-group">
                    <label>Name</label>
                    <input type="text" placeholder="Name" name="comname" maxlength="49" value="<?php echo $ckname; ?>" size="22" tabindex="1" class="input-sm form-control">
                  </div>
                  <div class="form-group">
                    <label>Email</label>
                    <input type="text" placeholder="Email" name="commail"  maxlength="128"  value="<?php echo $ckmail; ?>" size="22" tabindex="2" class="datepicker input-sm form-control">
                  </div>
                  <div class="form-group">
                    <label>Site</label>
                    <input type="text" placeholder="Site" name="comurl" maxlength="128"  value="<?php echo $ckurl; ?>" size="22" tabindex="3" class="input-sm form-control">
                  </div>
				  <?php endif; ?>
				  <div class="form-group">
                    <label>Comment</label>
					<textarea class="form-control" rows="5" placeholder="Type your comment" name="comment" id="comment" rows="10" tabindex="4"></textarea>
                  </div>
                  <div class="form-group">
                    <div>
                      <div class="btn-group">
                        <?php echo $verifyCode; ?>
                      </div>
                    </div>
                  </div>
                  <div class="m-t-lg">
				  
				  <button class="btn btn-sm btn-default" type="submit" id="comment_submit" tabindex="6">Submit comment</button>
				  <input type="hidden" name="pid" id="comment-pid" value="0" size="22" tabindex="1"/>
				  </div>
                </form>
				</div>
				</div>
	<?php }endif; ?>
<?php }?>
<?php
//******************************************相关页面数据调用函数*****************************************************//
//listen播放页视频
function YoukuMp3($order, $num1, $num2, $sort_id){
	$log_Model = new Log_Model;
	$logs = $log_Model->getLogsForHome("and top!='y' and sortop!='y' and sortid in (".implode(',', _g(''.$sort_id.'')).") ORDER BY $order DESC", $num1, $num2);
	foreach($logs as $key=>$row){
	$row['title'] = htmlspecialchars(trim($row['title']));
	$row['excerpt'] = nohtml($row['content']);
	if($sort_id == 'Youku_SortId'){
	?>
                      <div class="item pos-rlt">
                        <a href="<?php echo Url::log($row['gid']);?>" class="item-overlay active opacity wrapper-md font-xs <?php if((abs($key)+2)%2==1){; ?>text-right<?php }else{}; ?>">
                          <span class="block h3 font-bold <?php if($key=='0'){echo 'text-info';
						  }if($key=='1'){echo 'text-warning';
						  }if($key=='2'){echo 'text-success';
						  }if($key=='3'){echo 'text-white';
						  }if($key=='4'){echo 'text-danger-lter';
						  } ?> text-u-c">
						  <?php 
						  global $CACHE; 
						  $log_cache_sort = $CACHE->readCache('logsort');
						  echo $log_cache_sort[$row['gid']]['name']; ?>
						  </span>
                          <span class="text-muted"><?php echo $row['title'];?></span>
                          <span class="bottom wrapper-md block">- <i class="icon-arrow-right i-lg <?php if((abs($key)+2)%2==1){; ?>pull-left<?php }else{;?>pull-right<?php }; ?>"></i></span>
                        </a>
                        <a href="<?php echo Url::log($row['gid']);?>">
                          <img class="img-full" src="<?php echo YoukuImg($row['content'],$row['gid']);?>" alt="<?php echo $row['title'] ;?>">
                        </a>
                      </div>
					  <?php }
					  if($sort_id == 'Xiami_SortId'){;?>
                      <li class="list-group-item clearfix">
                        <a href="<?php echo Url::log($row['gid']);?>" class="jp-play-me pull-right m-t-sm m-l text-md">
                          <i class="icon-control-play text"></i>
                          <i class="icon-control-pause text-active"></i>
                        </a>
                        <a href="<?php echo Url::log($row['gid']);?>" class="pull-left thumb-sm m-r">
                          <img src="<?php echo TingImage($row['content'], $row['gid']); ?>" alt="<?php echo $row['title'] ;?>">
                        </a>
                        <a class="clear" href="<?php echo Url::log($row['gid']);?>">
                          <span class="block text-ellipsis"><?php echo $row['title'] ;?></span>
                          <small class="text-muted"><?php ting_xiami_tags($row['gid']); ?></small>
                        </a>
                      </li>
					  <?php }
}
}
//echo_xiami_log播放页 mp3
function ting_xiami_bottom_log($num1, $num2, $order){
	$log_Model = new Log_Model;
	$logs = $log_Model->getLogsForHome("and top!='y' and sortid in (".implode(',', _g('Xiami_SortId')).") ORDER BY $order DESC", $num1, $num2);
	foreach($logs as $key=>$row){
	$row['title'] = htmlspecialchars(trim($row['title']));
	?>
                      <li class="list-group-item">
                        <div class="pull-right m-l">
                          <!--<a href="#" class="m-r-sm"><i class="icon-cloud-download"></i></a>
                          <a href="#"><i class="icon-close"></i></a>-->
                        </div>
                        <a href="<?php echo Url::log($row['gid']);?>" class="jp-play-me m-r-sm pull-left">
                          <i class="icon-control-play text"></i>
                          <i class="icon-control-pause text-active"></i>
                        </a>
						
                        <div class="clear text-ellipsis" data-xiami-id="<?php echo XiamiId($row['content']); ?>">
						  <a href="<?php echo Url::log($row['gid']);?>" >
                          <span><?php echo $row['title'];?></span>
						  </a>
                          <span class="text-muted"></span>
                        </div>
                      </li>
<?php continue;}
}
//echo_xiami_log播放页 mp3
function ting_xiami_list($num1, $num2, $order, $type){
	$log_Model = new Log_Model;
	$logs = $log_Model->getLogsForHome("and top!='y' and sortid in (".implode(',', _g('Xiami_SortId')).") ORDER BY $order DESC", $num1, $num2);
	foreach($logs as $key=>$row){
	$row['title'] = htmlspecialchars(trim($row['title']));
	if($type == 'js'){
	?>
	{
      title:"<?php echo $row['title'];?>",
      artist:"<?php Cache_r($row['content'], $row['gid'], 'xmname'); ?>",
      mp3:"<?php Cache_r($row['content'], $row['gid'], 'xmurl'); ?>",
      poster: "<?php XiamiImg($row['content'], $row['gid'])?>"
    }
	<?php if($key !== '$num2-1'){echo ',';}
	}else{?>
                      <li class="list-group-item">
                        <div class="pull-right m-l">
                          
                          <a href="<?php echo Cache_r($row['content'], $row['gid'], 'xmurl'); ?>"><i class="icon-plus"></i></a>
                        </div>
                        <a href="<?php echo Cache_r($row['content'], $row['gid'], 'xmurl'); ?>" class="jp-play-me m-r-sm pull-left">
                          <i class="icon-control-play text"></i>
                          <i class="icon-control-pause text-active"></i>
                        </a>
                        <div class="clear text-ellipsis">
                          <span><?php echo $row['title'];?></span>
                          <span class="text-muted"></span>
                        </div>
                      </li>
					  <?php
	}continue;
	}
	
}
//echo_xiami_log播放页 关键词
function ting_xiami_tags($blogid){
	global $CACHE;
	$log_cache_tags = $CACHE->readCache('logtags');
	if (!empty($log_cache_tags[$blogid])){
		$tagT = 'Tags: &nbsp;&nbsp;';
		foreach ($log_cache_tags[$blogid] as $value){
			$tagT .= "	<a href=\"".Url::tag($value['tagurl'])."\" class=\"badge bg-light\">".$value['tagname'].'</a>';
		}
		echo $tagT;
	}
}
//不带链接关键词
function a_tags($blogid){
	global $CACHE;
	$log_cache_tags = $CACHE->readCache('logtags');
	if (!empty($log_cache_tags[$blogid])){
		$log_cache_tags[$blogid] = array_slice($log_cache_tags[$blogid],0,1);
		foreach ($log_cache_tags[$blogid] as $value){
			$taga .= $value['tagname'];
		}
		return $taga;
	}
}
//首页日志
function index_log($num1,$num2,$order, $Sort_id){
	$log_Model = new Log_Model;
	$logs = $log_Model->getLogsForHome("and top!='y' and sortop!='y' and sortid in (".implode(',', _g(''.$Sort_id.'')).") ORDER BY $order DESC", $num1, $num2);
	foreach($logs as $key=>$row){
	$row['title'] = htmlspecialchars(trim($row['title']));
	$row['excerpt'] = nohtml($row['content']);
	if($order=='date' && $Sort_id!=='Xiami_SortId'){
	?>
                    <div class="clearfix visible-xs"></div>
                    <div class="col-xs-6 col-sm-4 col-md-3 col-lg-2">
                      <div class="item">
                        <div class="pos-rlt">
                          <div class="item-overlay opacity r r-2x bg-black">
                            
                            <div class="center text-center m-t-n">
                              <a href="<?php echo Url::log($row['gid']);?>"><i class="icon-control-play i-2x"></i></a>
                            </div>
                          </div>
                          <a href="<?php echo Url::log($row['gid']);?>">
						 <img src="<?php TingImage($row['content'], $row['gid']); ?>" height="85" alt="<?php echo $row['title'] ;?>" class="r r-2x img-full"></a>
                        </div>
                        <div class="padder-v">
                          <a href="<?php echo Url::log($row['gid']);?>" class="text-ellipsis"><?php echo $row['title'] ;?></a>
                          <small class="text-ellipsis text-xs text-muted"><?php echo Sort_name($row['gid']) ;?></small>
                        </div>
                      </div>
                    </div>
	<?php continue;
	      }if($Sort_id=='Xiami_SortId'){?>
                        <div class="col-xs-6 col-sm-3">
                          <div class="item">
                            <div class="pos-rlt" data-xiami-id="<?php echo XiamiId($row['content']);?>">
                              <div class="item-overlay opacity r r-2x bg-black">
                                <div class="center text-center m-t-n">
                                  <a href="<?php echo Url::log($row['gid']);?>"><i class="fa fa-play-circle i-2x"></i></a>
                                </div>
                              </div>
                              <a href="<?php echo Url::log($row['gid']);?>">
							  <img src="<?php TingImage($row['content'], $row['gid']); ?>" height="120" alt="<?php echo $row['title'] ;?>" class="r r-2x img-full"></a>
                            </div>
                            <div class="padder-v">
                              <a href="<?php echo Url::log($row['gid']);?>" class="text-ellipsis"><?php echo $row['title'] ;?></a>
                              <small class="text-ellipsis text-xs text-muted"><?php echo Sort_name($row['gid']) ;?></small>
                            </div>
                          </div>
                        </div>
	<?php continue;
	      }if($order=='views'){?>
                        <a href="<?php echo Url::log($row['gid']);?>" class="list-group-item clearfix">
                          <span class="pull-right h2 text-muted m-l"><?php echo $key+1 ;?></span>
                          <span class="pull-left thumb-sm avatar m-r">
                            <img src="<?php TingImage($row['content'], $row['gid']); ?>" alt="<?php echo $row['title'] ;?>" height="45">
                          </span>
                          <span class="clear">
                            <span><?php echo $row['title'] ;?></span>
                            <small class="text-muted clear text-ellipsis">by 
							<?php global $CACHE; $log_cache_sort = $CACHE->readCache('logsort');
							if(!empty($log_cache_sort[$row['gid']])):
							echo $log_cache_sort[$row['gid']]['name'];
							endif;?></small>
                          </span>
                        </a>
<?php continue;}
	}
}
//all边栏日志
function side_log($num1,$num2,$order){
	$log_Model = new Log_Model;
	$logs = $log_Model->getLogsForHome("and top!='y' ORDER BY $order DESC", $num1, $num2);
	?>
                 <!--<div class="panel-heading">News</div>-->
                    <div class="panel-body">
	<?php 
	foreach($logs as $key=>$row){
	$row['title'] = htmlspecialchars(trim($row['title']));
	?>
                      <article class="media">
                        <a href="<?php echo Url::log($row['gid']);?>" class="pull-left thumb-lg m-t-xs">
                          <img src="<?php TingImage($row['content'], $row['gid']); ?>" alt="<?php echo $row['title'];?>">
                        </a>
                        <div class="media-body">                        
                          <a href="<?php echo Url::log($row['gid']);?>" class="font-semibold"><?php echo $row['title'];?></a>
                          <div class="text-xs block m-t-xs"><?php echo Sort_name($row['gid']);?><?php echo gmdate('M d, Y', $row['date']); ?></div>
                        </div>
                      </article> 
<?php continue;}
}
//列表页置顶日志
function log_list_top($num1,$num2,$order){
	$log_Model = new Log_Model;
	$logs = $log_Model->getLogsForHome("and (top='y' or sortop='y') ORDER BY $order DESC", $num1, $num2);
	foreach($logs as $key=>$row){
	$row['title'] = htmlspecialchars(trim($row['title']));
	?>
                <div class="col-xs-12 col-sm-4">
                  <div class="item">
                    <div class="pos-rlt">
                      <div class="item-overlay opacity r r-2x bg-black">
                        <div class="center text-center m-t-n">
                          <a href="<?php echo Url::log($row['gid']);?>"><i class="fa fa-play-circle i-2x"></i></a>
                        </div>
                      </div>
                      <div class="top">
                        <span class="badge bg-dark m-l-sm m-t-sm"></span>
                      </div>
                      <a href="<?php echo Url::log($row['gid']);?>">
					  <img src="<?php TingImage($row['content'],$row['gid']);?>" height="205" alt="<?php echo $row['title'];?>" class="r r-2x img-full"></a>
                    </div>
                    <div class="padder-v">
                      <a href="<?php echo Url::log($row['gid']);?>" class="text-ellipsis"><?php echo $row['title'];?></a>
                      <a href="<?php echo Url::log($row['gid']);?>" class="text-ellipsis text-xs text-muted"><?php echo Sort_name($row['gid']);?></a>
                    </div>
                  </div>
                </div>
<?php continue;}
}
//echo_xiami_log 艺人档案tab
function xiami_yiren($logid, $Sort_id){
	$keyword = a_tags($logid);
	$log_Model = new Log_Model;
	$logs = $log_Model->getLogsForHome("and sortid in (".implode(',', _g(''.$Sort_id.'')).") and title like '%{$keyword}%' order by date desc", 0, 1);
	if($logs){
	foreach($logs as $key=>$row){
	$row['title'] = htmlspecialchars(trim($row['title']));
	echo extractHtmlData($row['content'],500);?>
	<p></p>
	<a href="<?php echo Url::log($row['gid']);?>" class="btn btn-default">更多详情</a>
	<?php continue;}
	}
}
//echo_xiami_log 相关mv和mp3 tab
function xiami_mvmp3($num1, $num2, $logid, $Sort_id, $order){
	$keyword = a_tags($logid);
	$log_Model = new Log_Model;
	$logs = $log_Model->getLogsForHome("and title like '%{$keyword}%' and sortid in (".implode(',', _g(''.$Sort_id.'')).") ORDER BY $order DESC", $num1, $num2);
	if($logs){
	foreach($logs as $key=>$row){
	$row['title'] = htmlspecialchars(trim($row['title']));
	?>
                <div class="col-xs-12 col-sm-4">
                  <div class="item">
                    <div class="pos-rlt">
                      <div class="item-overlay opacity r r-2x bg-black">
                        <div class="center text-center m-t-n">
                          <a href="<?php echo Url::log($row['gid']);?>"><i class="fa fa-play-circle i-2x"></i></a>
                        </div>
                      </div>
                      <div class="top">
                        <span class="badge bg-dark m-l-sm m-t-sm"></span>
                      </div>
                      <a href="<?php echo Url::log($row['gid']);?>">
					  <img src="<?php TingImage($row['content'],$row['gid']);?>" alt="<?php echo $row['title'];?>" height="180" class="r r-2x img-full"></a>
                    </div>
                    <div class="padder-v">
                      <a href="<?php echo Url::log($row['gid']);?>" class="text-ellipsis"><?php echo $row['title'];?></a>
                      <a href="<?php echo Url::log($row['gid']);?>" class="text-ellipsis text-xs text-muted"><?php echo Sort_name($row['gid']);?></a>
                    </div>
                  </div>
                </div>
	<?php continue;}
	}
}?>